package com.nervenets.template.service.impl;

import com.aliyuncs.CommonRequest;
import com.aliyuncs.CommonResponse;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.http.MethodType;
import com.aliyuncs.profile.DefaultProfile;
import com.nervenets.template.service.AliyunService;
import org.springframework.stereotype.Service;

@Service
public class AliyunServiceImpl implements AliyunService {

    private final static String accessKeyId = "LTAI4G7r5uvuxTLQ6NkfeTi7";
    private final static String accessKeySecret = "dX7LOwFfxw0nXNNvsjKtKmVrJSS3j4";

    public CommonResponse sendZhSms(String mobile, String code) throws ClientException {
        DefaultProfile profile = DefaultProfile.getProfile("default", accessKeyId, accessKeySecret);
        IAcsClient client = new DefaultAcsClient(profile);

        CommonRequest request = new CommonRequest();
        //request.setProtocol(ProtocolType.HTTPS);
        request.setMethod(MethodType.POST);
        request.setDomain("dysmsapi.aliyuncs.com");
        request.setVersion("2017-05-25");
        request.setAction("SendSms");
        request.putQueryParameter("PhoneNumbers", mobile);
        request.putQueryParameter("SignName", "好好学");
        request.putQueryParameter("TemplateCode", "SMS_201690032");
        request.putQueryParameter("TemplateParam", "{\"code\":\"" + code + "\"}");
        return client.getCommonResponse(request);
    }
}
